<?php

namespace App\Console\Commands;

use App\Events\UploadIdCardEvent;
use App\Facades\SamLogFacade;
use App\Models\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;

class CheckUserIdCardUploadCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'checkIdCardUpload';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'check id card upload';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $users = User::Join('user_cert_ocrs','users.id','=','user_cert_ocrs.user_id')
            ->whereNull('user_cert_ocrs.upload')
            ->whereNotNull('users.nfsp_user_id')
            ->select(['users.id','users.nfsp_user_id'])
            ->get();
        if($users->count()>0){
            foreach ($users as $index =>$user){
                event(new UploadIdCardEvent($user));
            }
            SamLogFacade::debug("检测到{$users->count()}个已同步用户未上传身份证,已经推入上传队列");
        }
    }
}
